package com.shujia.hive;

import java.sql.*;

public class Demo01HiveJDBC {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        // 1、加载驱动
        Class.forName("org.apache.hive.jdbc.HiveDriver");
        // 2、建立连接
        Connection conn = DriverManager.getConnection("jdbc:hive2://master:10000/test3","root","");
        // 3、创建statement
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery("select * from students limit 10");
        while (rs.next()) {
            int id = rs.getInt(1);
            String name = rs.getString(2);
            int age = rs.getInt(3);
            String gender = rs.getString(4);
            String clazz = rs.getString(5);
            System.out.println(id + "," + name + "," + age + "," + gender + "," + clazz);
        }
        rs.close();
        stat.close();
        conn.close();
    }

}
